<template>
  <div class="app-container">
    <div class="sds-content">
      <span>状态：</span>
      <el-radio-group v-model="status" @input="handleChange">
        <el-radio :label="true">开始停服</el-radio>
        <el-radio :label="false">解除停服</el-radio>
      </el-radio-group>
      <div class="tip">注：功能启动后，用户在指定时间内无法登录工场平台，在平台中的用户将被登出。</div>
    </div>
  </div>
</template>
<script>
import { getWorkshopSysEnableStatus, updateWorkshopSysEnableStatus } from '@/api/system/timing'
export default {
  name: 'ShutDownSetting',
  data() {
    return {
      status: false// 0代表关闭（默认管理），1代表开启
    }
  },
  created() {
    this.getStatus()
  },
  methods: {
    getStatus() {
      getWorkshopSysEnableStatus().then(res => {
        this.status = res
      })
    },
    handleChange(v) {
      this.status = !this.status // 消除已更新值的影响
      const message = v ? '开始停服' : '解除停服'
      this.$confirm(`确定${message}？`, '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        closeOnClickModal: false,
        type: 'warning'
      }).then(() => {
        updateWorkshopSysEnableStatus(v).then(() => {
          this.$message.success(`已${message}`)
          this.status = v
        }).catch(e => {
          this.$message.error(e)
        })
      })
    }
  }
}
</script>

<style scoped lang="scss">
.sds-content{
  height: calc(100vh - 170px);
  margin: 19px 0 0 8px;
  font-size: 16px;
  span{
    margin-right: 10px;
  }
  ::v-deep .el-radio-group{
    transform: scale(1.2);
    transform-origin: left;
  }
  ::v-deep .el-radio__label {
      font-size: 13px;
  }
  .tip{
    font-size: 13px;
    color: var(--brother-common-pagination-text-color);
    height: 30px;
    line-height: 75px;
  }
}
</style>
